package com.zr.dao.impl;

import java.util.List;


import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.zr.dao.PointDao;
import com.zr.model.Point;
import com.zr.model.Psfwb;

@Repository("pointdao")
public class PointdaoImpl<T> extends BaseDaOImpl<T> implements PointDao<T>{
	
	@Override
	public List<Point> findAllPoint(int page, int rows) {
		String hql = "from Point";
    	Query query = this.getCurrentSession().createQuery(hql);
    	query.setFirstResult((page-1)*rows);// 璧峰浣嶇疆
    	query.setMaxResults(rows);//璁板綍鏁�
    	List<Point> ts = query.list();
    	StringBuffer s = new StringBuffer();
    	for (Point p : ts) {
    		s.delete(0,s.length()); 
			int pid1= p.getPid();
			String hql1 = "from Psfwb where pid=:pid1";
			Query query1 = this.getCurrentSession().createQuery(hql1);
			query1.setInteger("pid1", pid1);
			List<Psfwb> ts1 = query1.list();
			for (int i = 0; i < ts1.size(); i++) {
				s.append(ts1.get(i).getDname()+",");
			}
			String q = s.toString();
			p.setDname(q);
		}
		return ts;
	}

	@Override
	public long countAllpoint() {
		String hql = "select count(*) from Point";
		List<Object>  obj = this.getCurrentSession().createQuery(hql).list();
		return (long)obj.get(0);
	}
	
}
